home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 10 Scripting / 02 Berger / sinterp / Opcode.H < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-15  |  1.3 KB  |  45 lines

  1. #ifndef __Opcodes_H__
  2. #define __Opcodes_H__
  3.  
  4.  
  5. // This enumeration defines the set of opcodes that the interpreter
  6. // understands.  The code generator needs to use this enumeration to generate
  7. // the proper bytecode stream, and the interpreter uses this enumeration to
  8. // actually evaluate the instructions.
  9. enum Opcode {
  10.   // Define the four basic math opcodes.
  11.   Add_Opcode,
  12.   Subtract_Opcode,
  13.   Multiply_Opcode,
  14.   Divide_Opcode,
  15.  
  16.   // Push & pop add and remove a value from the interpreter's stack.
  17.   Push_Opcode,
  18.   Pop_Opcode,
  19.  
  20.   // The dupe opcode takes the stack element and pushes a copy of it onto the
  21.   // stack.
  22.   Dupe_Opcode,
  23.  
  24.   // These two opcodes loads and stores a variable off of the stack.  The
  25.   // opcode's argument is the offset (in stack words) from the first element
  26.   // in the stack where the variable exists.
  27.   Load_Opcode,
  28.   Store_Opcode,
  29.  
  30.   // Increments the instruction pointer by the opcode's argument (i.e., a
  31.   // relative jump).
  32.   Jump_Opcode,
  33.  
  34.   // Pops the stack element off and increments the instruction pointer by
  35.   // the opcode's argument if the stack element is zero (i.e., performs a
  36.   // relative jump on zero).
  37.   IfZero_Opcode,
  38.  
  39.   // This simply defines the maximum number of opcodes used.
  40.   Num_Opcode
  41. };
  42.  
  43.  
  44. #endif // __Opcodes_H__
  45.